package xin.yangshuai.juc01.hello;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * Question4
 *
 * @author shuai
 * @date 2022/2/12
 */
public class Question4 {

}

class Result4 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> futureTask1 = new FutureTask<Integer>(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int num = 0;
                for (int i = 0; i < 101; i++) {
                    num = num + i;
                }
                TimeUnit.SECONDS.sleep(5);
                System.out.println(Thread.currentThread().getName() + " :: " + num);
                return num;
            }
        }){
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + " :: run");
                super.run();
            }
        };
        new Thread(futureTask1, "AA").start();

        Integer integer = futureTask1.get();
        System.out.println(integer);

        System.out.println(Thread.currentThread().getName() + " :: over");


    }
}
